<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no">
    <title>Car1</title>
    <link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet">
    <script src="https://unpkg.com/video.js/dist/video.min.js"></script>
</head>
<body>
<h1>WebSocket Example</h1>
<p>接收到的消息：</p>
<ul id="messages"></ul>
<p>视频：</p>
<!-- 设置播放器容器 -->
<video id="my-video"muted="muted" loop="true" width="1264" height="720" autoplay="true" class="video-js" controls preload="auto" width="640" height="264" data-setup="{}">
    <source src="http://1309991848.vod2.myqcloud.com/4e0caab6vodcq1309991848/a17ac059243791579147817045/f0.mp4" type="video/mp4">
</video>
<script>
    const video = videojs('my-video', {}, function () {
        // 播放器创建成功后的回调函数
        console.log('播放器创建成功');
    });
    // http://1309991848.vod2.myqcloud.com/4e0caab6vodcq1309991848/a17ac059243791579147817045/f0.mp4
    // http://1309991848.vod2.myqcloud.com/4e0caab6vodcq1309991848/0138b29c243791578556292516/f0.mp4
    // http://1309991848.vod2.myqcloud.com/4e0caab6vodcq1309991848/036cf062243791578556378427/f0.mp4
    const socket = new WebSocket('wss://mo.jamorantxff.fun/admin/vod/myHandler1');

    socket.onopen = function(event) {
        console.log('WebSocket 连接成功');
    };

    socket.onmessage = function(event) {
        console.log('接收到消息：', event.data);
        const messages = document.getElementById('messages');
        const li = document.createElement('li');
        li.textContent = event.data;
        messages.appendChild(li);
        // 播放器重新加载视频
        video.src({src: event.data, type: 'video/mp4'});
        video.load();
        video.play();
    };

    socket.onerror = function(event) {
        console.error('WebSocket 发生错误：', event);
    };

    socket.onclose = function(event) {
        console.log('WebSocket 连接关闭');
    };
</script>
</body>
</html>
